-- This file is hereby placed in the Public Domain
local addonName, ns = ...
local addon = ns[addonName]
local oUF = ns.oUF

local utils = addon.utils
local units = 'focus'

local function func(self, unit)
    local tex = self:CreateTexture(nil, 'ARTWORK')
    tex:SetTexture(utils.mediaPath .. 'PartyFrame')
    tex:SetPoint('CENTER', self, -6, -6)
    utils.setSize(tex, 256 * .8, 128 * .8)
    self.texture = tex

    local bg = self.bg:CreateTexture(nil, 'BACKGROUND')
    bg:SetTexture(utils.mediaPath .. 'PartyBackground')
    bg:SetPoint('CENTER', self, -6, -6)
    utils.setSize(bg, 256 * .8, 128 * .8)
    self.bg_tex = bg

    local hp = CreateFrame('StatusBar', nil, self)
    self.Health = hp
    hp:SetPoint("TOPRIGHT", self, "TOPRIGHT", 5, -60)
    hp:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", 20, 10) --"BOTTOMRIGHT", -85, 8)
    hp:SetFrameStrata("LOW")
    hp:SetFrameLevel(3)
    hp:SetStatusBarTexture(utils.mediaPath.."normTex")
    hp:SetStatusBarColor(0.2, 0.2, 0.2)
--    hp.colorSmooth = true
    hp.frequentUpdates = true
    hp.colorHappiness = false
    hp.colorClass = true
    hp.Smooth = true
    hp.colorClass = true

    hp.bg = hp:CreateTexture(nil, "BORDER")
    hp.bg:SetAllPoints(hp)
		    --	hp:SetAlpha(.5)
    hp.bg:SetTexture(utils.mediaPath .. 'PlayerBackground')
    hp.bg:SetVertexColor(.15,.15,.15)
    hp.bg.multiplier = ns.colorMultiplier

		    --    mp:SetReverse(true)
		    --    self.Power = mp
		    --    utils.setSize(mp, WIDTH, HEIGHT)
		    --    mp:SetPoint('BOTTOMRIGHT', 0, 3)
		    --    mp.colorPower = true

--    mp = CreateFrame( "StatusBar", nil, self)
--    self.Power = mp
--    mp:SetPoint("TOPRIGHT", self,"BOTTOMRIGHT", 40, 8)
--    mp:SetPoint("BOTTOMLEFT", self,"BOTTOMRIGHT", 0, 4) 	
--    mp:SetFrameStrata("LOW")
--    mp:SetFrameLevel(3)
--    mp:SetStatusBarTexture(utils.mediaPath.."rothTex")
--    mp.colorSmooth = true
--    mp.colorPower = true
--    mp.frequentUpdates = true
--    mp.colorTapping = true
--    mp.colorDisconnected = true
--    mp.colorPower = true
--    mp.colorReaction = true

--    mp.bg = mp:CreateTexture(nil, 'BORDER')
--    mp.bg:SetAllPoints(mp)
--    mp.bg:SetTexture(utils.mediaPath .. 'rothTex')
--    mp.bg.multiplier = ns.colorMultiplier
--    mp.bg.multiplier = .45
		    

    local portrait = CreateFrame('PlayerModel', nil, self)
    portrait:SetFrameStrata('BACKGROUND')
    portrait:SetHeight(30)
    portrait:SetWidth(40)
    portrait:SetPoint('BOTTOMLEFT', self, -25,30)
    self.Portrait = portrait

    local castbar  = CreateFrame('StatusBar', nil, self)
    self.Castbar = castbar
    castbar:SetFrameStrata('LOW')
    castbar:SetFrameLevel(3)
    castbar:SetStatusBarTexture(utils.mediaPath.."rothTex")
    castbar:SetStatusBarColor(0/255, 159/255, 233/255)
    utils.setSize(caster, 115, 10)    
    
    castbar.Button = CreateFrame('Frame', nil, self.Castbar)
    castbar.Button:SetHeight(32)
    castbar.Button:SetWidth(32)
    castbar.Button:SetBackdrop(backdrop)
    castbar.Button:SetBackdropColor(0, 0, 0)
    castbar.Icon = castbar.Button:CreateTexture(nil, 'ARTWORK')
    castbar.Icon:SetAllPoints(castbar.Button)
    castbar.Icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
    
    castbar.Text = castbar:CreateFontString(nil, 'OVERLAY')
    castbar.Text:SetFont(STANDARD_TEXT_FONT, 13, 'OUTLINE')
    castbar.Text:SetPoint('RIGHT', -5, 20)
    castbar.Text:SetTextColor(153/255,204/255,242/255)
    castbar.Text:SetJustifyH("RIGHT")

    castbar.Time = castbar:CreateFontString(nil, 'OVERLAY')
    castbar.Time:SetFont(STANDARD_TEXT_FONT, 12, 'THINOUTLINE')
    castbar.Time:SetTextColor(255/255,255/255,190/255)
    castbar.Time:SetJustifyH("LEFT")
    castbar.CustomTimeText = utils.castbarTime
    castbar.Time:SetPoint("RIGHT", -5, 0)

    castbar:SetOrientation('VERTICAL')
    castbar:SetFrameStrata('BACKGROUND')
    castbar.Button:SetFrameLevel(2)
    castbar.Button:SetAllPoints(castbar)
    castbar:SetStatusBarColor(0/255, 159/255, 233/255,.65)
    castbar:SetHeight(40)
    castbar:SetWidth(40)
    castbar:SetPoint('LEFT', 100,-5)
    castbar.Text:SetPoint('CENTER', 2,2)
    castbar.Text:SetJustifyH('CENTER')
    castbar.Time:SetPoint("LEFT" , -30 , 0)

    self.RaidIcon = self.Health:CreateTexture(nil, 'OVERLAY')
    self.RaidIcon:SetHeight(10)
    self.RaidIcon:SetWidth(10)
    self.RaidIcon:SetPoint('TOP', 0, 10)
    --self.RaidIcon:SetParent(oUFTagHolder)

    self.IconBackdrop = iconBackdrop
    self.IconBackdrop = CreateFrame('Frame', nil, self)
    self.IconBackdrop:SetPoint('TOPRIGHT', self.Castbar, 3, 3)
    self.IconBackdrop:SetPoint('BOTTOMLEFT', self.Castbar, -3, -3)

----------------------------------------------------------------------------
    local nametag = self:CreateFontString(nil, 'OVERLAY')
    nametag:SetPoint('TOP', self, 'BOTTOM', 0, -2)
    nametag:SetFont(STANDARD_TEXT_FONT, 12, 'OUTLINE')
    self:Tag(nametag, addon.tags.name)
end

addon:addLayoutElement(units, func)
addon:setSize(units, 90, 90)

addon:spawn(function()
    local u = addon.units
    local focus = oUF:Spawn('focus')
    focus:SetPoint('BOTTOMRIGHT', u.player, 'TOPLEFT', -100, -80)
    u.focus = focus
end)


